package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo11 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            String sql = "INSERT INTO userinfo (username,password,nickname,age) VALUES (?,?,?,?)";
            connection.setAutoCommit(false);
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, "鲁鲁修VI布里塔尼亚");
            preparedStatement.setString(2, "886886886");
            preparedStatement.setString(3, "鲁鲁修");
            preparedStatement.setInt(4, 20);
            int number = preparedStatement.executeUpdate();
            System.out.println(number > 0 ? "提交成功" : "提交失败");
            //connection.rollback();
            connection.commit();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
